package secondkill.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * RabbitMQ Topic模式的配置文件
 * @Auther  丁子川
 * @create 2022/1/19 13:03
 */

@Configuration
public class RabbitMQTopicConfig {

    private static final String QUEUE = "seckillQueue";

    private static final String EXCHANGE = "seckillExchange";

    @Bean
    //配置队列
    public Queue queue() {
        return new Queue(QUEUE);
    }

    @Bean
    //配置交换机
    public TopicExchange topicExchange() {
        return new TopicExchange(EXCHANGE);
    }

    @Bean
    //队列绑定交换机
    public Binding binding() {
        return BindingBuilder.bind(queue()).to(topicExchange()).with("seckill.#");
    }
}
